package daily;

/**
 * @author MtRider
 * @version 1.0
 * @description 买卖股票的最佳时机 II
 * @GiteeAndGithub MtRider
 * @date 2022/4/20 17:56
 */
public class demo02 {
    public static void main(String[] args) {
        int[] prices={7,6,4,3,1};
        System.out.println(maxProfit(prices));
    }
    //把当天股价比前一天股价高的差值加起来，返回即可
    public static int maxProfit(int[] prices) {
        int sum=0;
        for (int i = 0; i < prices.length-1; i++) {
            if(prices[i]<prices[i+1]){
                sum+=prices[i+1]-prices[i];
            }
        }
        return sum;

    }
}
